package com.bolt.report.engine.model;

import java.util.List;

public class PageDetails extends BaseBand {

    public PageDetails() {
        super();
    }

    public PageDetails(List<Column> columns) {
        super();
        setColumns(columns);
    }

    public PageDetails(List<Column> columns, List<Row> rows) {
        super();
        setColumns(columns);
        setRows(rows);
    }

    public List<Column> getColumn() {
        return table.getColumns();
    }

    public Cell findCell(int rowIndex, int cellIndex) {
        List<Row> allRow = getTable().getRows();
        if (rowIndex >= allRow.size()) {
            return null;
        }
        Row row = allRow.get(rowIndex);
        return row.getCell(cellIndex);
    }

    public Cell findLastCell(int cellIndex) {
        Cell cell = null;
        List<Row> allRow = getTable().getRows();
        for (int i = allRow.size() - 1; i >= 0; i--) {
            Row row = allRow.get(i);
            cell = row.getCell(cellIndex);
            if (cell != null) {
                break;
            }
        }
        return cell;
    }

    public Cell findLastGroupCell(int cellIndex) {
        Cell cell = null;
        List<Row> allRow = getTable().getRows();
        for (int i = allRow.size() - 1; i >= 0; i--) {
            Row row = allRow.get(i);
            cell = row.getCell(cellIndex);
            if (cell != null && cell.getRowSpan() > 0) {
                break;
            }
        }
        return cell;
    }

    public Cell getRowSpanCell() {
        Cell rowSpanCell = null;
        int rowSize = getTable().getRows().size();
        for (Row row : getTable().getRows()) {
            for (Column column : getTable().getColumns()) {
                Cell cell = row.getCell(column);
                if (cell == null) continue;
                int rowSpan = cell.getRowSpan();
                if (rowSpan > rowSize) {
                    rowSpanCell = cell;
                    break;
                }
            }
        }
        return rowSpanCell;
    }

    public int getRowSize() {
        return this.table.getRows().size();
    }

    public List<Row> getRow() {
        return table.getRows();
    }



}